package com.xiaobawang.xjsyy_idea_plugin.panel.dev_process.view;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellRenderer;
import java.awt.*;

public class JPanelTableCellRenderer implements TableCellRenderer {

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());

        // 根据 value 创建组件并添加到 JPanel 中
        if (value instanceof String) {
            JLabel label = new JLabel((String) value);
            panel.add(label, BorderLayout.CENTER);
        } else if (value instanceof Component) {
            panel.add((Component) value);
        }

        // 可以在这里添加更多的定制化逻辑，比如边框、背景颜色等

        // 如果单元格被选中，可以修改 JPanel 的外观
        if (isSelected) {
            panel.setBackground(table.getSelectionBackground());
            panel.setForeground(table.getSelectionForeground());
        } else {
            panel.setBackground(table.getBackground());
            panel.setForeground(table.getForeground());
        }

        return panel;
    }
}